const Koa = require('koa')
const app = new Koa()
const router = require('./router');
const views = require("koa-views");
const serv = require('koa-static');
const koaBody = require('koa-body');
const path = require('path');
app.use(koaBody());
// 设置模版引擎
app.use(views(path.join(__dirname, "views"), {
  map: {
    html: 'underscore'
  }
}));
// 跨域设置
app.use(async (ctx, next) => {
  ctx.set("Access-Control-Allow-Origin", "*");
  await next();
})

app.use(router.routes());
app.use(serv(__dirname + '/public'));

app.listen(3000, () => {
  console.log('服务已启动，在 http://localhost:3000/');
});
